<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    .name {
      display: inline-block;
      width: 100px;
    }
    .price {
      display: inline-block;
      /* width: 50px; */
    }
    .num {
      display: inline-block;
      /* width: 30px; */
    }
  </style>
</head>
<body>
  <div id="app">
    <p>{{message}}</p>
    <p>{{reverseMsg}}</p>
    <hr>
    <span class="name">{{cartInfo[0].name}}</span>
    <span class="price">{{cartInfo[0].price}}</span>
    <span class="num">{{cartInfo[0].num}}</span>
    <br>
    <span class="name">{{cartInfo[1].name}}</span>
    <span class="price"><input type="text" v-model="cartInfo[1].price"></span>
    <span class="num">{{cartInfo[1].num}}</span>
    <hr>
    <span>computed总计：{{totalPrice}}</span><br>
    <span>computed总计：{{totalPrice}}</span><br>
    <span>function总计：{{totalPrice1()}}</span><br>
    <span>function总计：{{totalPrice1()}}</span><br>
    <!-- <input v-model="userInfo1"> -->
    <span>用户的年龄：{{getUserAge}}</span>
  </div>
  <script src="../js/vue.js"></script>
  <script>
    let vm = new Vue({
      el: '#app',
      data: {
        message: '郑州职业技术学院',
        cartInfo: [
          {
            name: 'mi 10',
            price: '3999',
            num: 10
          },
          {
            name: 'iphone se2',
            price: '2999',
            num: 20
          }
        ],
        userAge: 0
      },
      computed: {
        reverseMsg: function() {
          return this.message.split('').reverse().join('')
        },
        totalPrice: function() {
          console.log('computed');
          let price = 0
          this.cartInfo.forEach(element => {
            price += element.price * element.num
          });
          return price
        },
        // userInfo1: {
        //   get: function() {
        //     return 1
        //   },
        //   set: function(newVal) {
        //     // debugger
        //     let str = newVal.substring(1);
        //     this.userAge = str.split('&')[1].split('=')[1]
        //   }
        // }
        getUserAge: function() {
          return location.search.substring(1).split('&')[1].split('=')[1]
        }
      },
      methods: {
        totalPrice1: function() {
          console.log('fn');
          let price = 0
          this.cartInfo.forEach(element => {
            price += element.price * element.num
          });
          return price
        }
      },
    })
  </script>
</body>
</html>